package com.xiaodu.validator.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.validation.groups.Default;
import java.util.Date;
import java.util.List;

/**
 * @author: dutianjie
 * @date: 2021/3/31
 * @version: v1.0.0
 * @description: 描述
 **/
@ApiModel(description = "订单信息描述")
public class OrderEntity {

    @ApiModelProperty(required = true, value = "订单编号")
    @Length(min = 32, max = 32, message = "orderId 长度为32", groups = OrderGroup.class)
    @NotBlank(message = "orderId 必填"/*, groups = OrderGroup.class*/)
    private String orderId;

    @ApiModelProperty(required = true, value = "订单创建时间")
    @NotNull
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    @ApiModelProperty(required = true, value = "订单详情")
    @NotNull
    @Valid
    private OrderInfo orderInfo;

    @ApiModelProperty(required = true, value = "商品信息")
    @NotNull
    @Size(max = 100, min = 1)
    private List<Product> productList;

    @ApiModelProperty(required = false, value = "备注")
    @Length(max = 255)
    private String remark;

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public OrderInfo getOrderInfo() {
        return orderInfo;
    }

    public void setOrderInfo(OrderInfo orderInfo) {
        this.orderInfo = orderInfo;
    }

    public List<Product> getProductList() {
        return productList;
    }

    public void setProductList(List<Product> productList) {
        this.productList = productList;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    @Override
    public String toString() {
        return "OrderEntity{" +
                "orderId='" + orderId + '\'' +
                ", createTime=" + createTime +
                ", orderInfo=" + orderInfo +
                ", productList=" + productList +
                ", remark='" + remark + '\'' +
                '}';
    }
    // 添加订单不需要订单编号，后台生成返回
    public interface OrderGroup {}

    @ApiModel(description = "订单扩展详情")
    public class OrderInfo {

        @ApiModelProperty(value = "订单来源", required = true)
        @Length(max = 32, min = 1)
        @NotBlank
        private String orderSource;

        public String getOrderSource() {
            return orderSource;
        }

        public void setOrderSource(String orderSource) {
            this.orderSource = orderSource;
        }

        @Override
        public String toString() {
            return "OrderInfo{" +
                    "orderSource='" + orderSource + '\'' +
                    '}';
        }
    }

}

